<!--会议上传页面-->
<template>
  <div style="margin: 20px; padding: 20px">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-form-item label="会议名称" prop="name">
        <el-input v-model="ruleForm.name" />
      </el-form-item>
      <el-form-item label="会议类型" prop="type">
        <el-select v-model="ruleForm.type" placeholder="请选择会议类型">
          <el-option label="个人会议" value="personal" />
          <el-option label="公司会议" value="business" />
          <el-option label="..." value="others" />
        </el-select>
      </el-form-item>
      <el-form-item label="会议时间" required>
        <el-col :span="11">
          <el-form-item prop="date1">
            <el-date-picker v-model="ruleForm.date1" type="date" placeholder="选择日期" style="width: 100%;" />
          </el-form-item>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-form-item prop="date2">
            <el-time-picker v-model="ruleForm.date2" placeholder="选择时间" style="width: 100%;" />
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item label="会议分析" prop="menu">
        <el-checkbox-group v-model="ruleForm.menu">
          <el-checkbox label="主题分析" name="subjectAnalysis" />
          <el-checkbox label="关键词分析" name="keyWordAnalysis" />
          <el-checkbox label="人员情绪分析" name="sentimentAnalysis" />
          <el-checkbox label="人员交互关系分析" name="interactAnalysis" />
        </el-checkbox-group>
      </el-form-item>
      <!--      文件上传-->
      <el-form-item label="会议上传" prop="file">
        <el-upload
          ref="upload"
          class="upload-demo"
          action="http://127.0.0.1:10086/smart-admin-api//api/file/localUpload/1"
          :on-preview="handlePreview"
          :on-remove="handleRemove"
          :on-error="uploadError"
          :auto-upload="false"
        >
          <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
          <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传</el-button>
          <div slot="tip" class="el-upload__tip">只能上传音视频文件</div>
        </el-upload>
      </el-form-item>

      <el-form-item label="会议说明" prop="desc">
        <el-input v-model="ruleForm.desc" type="textarea" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'MeetingUpload',
  data() {
    return {
      ruleForm: {
        name: '',
        type: '',
        date1: '',
        date2: '',
        menu: [],
        desc: '',
        fileList: []
      },
      rules: {
        name: [
          { required: true, message: '请输入会议名称', trigger: 'blur' },
          { min: 3, max: 20, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '请选择活动区域', trigger: 'change' }
        ],
        date1: [
          { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
        ],
        date2: [
          { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
        ],
        menu: [
          { type: 'array', required: true, message: '请至少选择一个功能性质', trigger: 'change' }
        ],
        file: [
          { type: 'file', require: true, message: '请上传会议音频/视频', trigger: 'blur' }
        ],
        desc: [
          { required: false, message: '请填写活动形式', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // alert('submit!');
          alert('需定义后端会议数据上传接口')
        } else {
          alert('需定义后端会议数据上传接口')
          // console.log('error submit!!');
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    handlePreview() {
      console.log(FileList)
    },
    submitUpload(res) {
      this.$refs.upload.submit()
      console.log(res)
    },
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    uploadError(e) {
      alert('上传出错，请重试')
      console.log(e)
    }
  }

}
</script>

<style scoped>

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 120px;
  height: 120px;
  line-height: 120px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}

</style>
